using FireStarterModeller.BO;
using FireStarterModeller.UI;
using Habanero.Faces.Base;
using NUnit.Framework;

namespace FireStarterModeller.Test.UI
{
    [TestFixture]
    public class TestSolutionControl
    {
        [TestFixtureSetUp]
        public void SetupFixture()
        {
            UITestUtils.SetupFixture();
        }


        [SetUp]
        public virtual void SetupTest()
        {
            UITestUtils.SetupTest();
        }

        [Test]
        public void Test_CreateControl()
        {
            //--------------- Set up test pack ------------------

            //--------------- Test Preconditions ----------------

            //--------------- Execute Test ----------------------
            CreateSolutionControl createSolutionControl = new CreateSolutionControl();
            //--------------- Test Result -----------------------
            Assert.AreEqual(2, createSolutionControl.Controls.Count);
            Assert.IsInstanceOf(typeof (IPanel), createSolutionControl.Controls[0]);
            Assert.IsInstanceOf(typeof (IButtonGroupControl), createSolutionControl.Controls[1]);
        }

        [Test]
        public void Test_ButtonGroupControl()
        {
            //--------------- Set up test pack ------------------

            //--------------- Test Preconditions ----------------

            //--------------- Execute Test ----------------------
            CreateSolutionControl createSolutionControl = new CreateSolutionControl();
            //--------------- Test Result -----------------------
            IButtonGroupControl buttonGroupControl = createSolutionControl.ButtonGroupControl;
            Assert.IsNotNull(buttonGroupControl);
            Assert.AreEqual(2, buttonGroupControl.Controls.Count);
            Assert.IsNotNull(buttonGroupControl["Save"]);
            Assert.IsNotNull(buttonGroupControl["Cancel"]);
        }

        [Test]
        public void Test_Save_ShouldCreateNewSolution()
        {
            //--------------- Set up test pack ------------------
            CreateSolutionControl createSolutionControl = new CreateSolutionControl();

            //--------------- Test Preconditions ----------------
            DMSolution dmSolution = createSolutionControl.DMSolution;
            Assert.IsNotNull(dmSolution);
            Assert.IsTrue(dmSolution.Status.IsNew);
            Assert.AreSame(dmSolution, createSolutionControl.PanelInfo.BusinessObject);
            //--------------- Execute Test ----------------------
            dmSolution.SolutionName = TestUtilsShared.GetRandomString();
            createSolutionControl.ButtonGroupControl["Save"].PerformClick();
            //--------------- Test Result -----------------------
            Assert.IsNotNull(dmSolution.DefaultAssembly);
            Assert.IsFalse(dmSolution.Status.IsNew);
        }
    }

}